#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

template<typename T>
void bubble_sort(vector<T> &arr) {
    for (ll i=0; i < arr.size(); i++)
        for (ll j=i; j < arr.size()-1; j++)
            if (arr[j] > arr[j+1])
                swap(arr[j], arr[j+1]);
}

vector<ll> readFileUntilEOF(ifstream &stream_) {
    vector<ll> arr;
    ll temp;
    while (!stream_.eof()) {
        stream_ >> temp;
        arr.push_back(temp);
    }
    stream_.close();
    return arr;
}

void sortWithMeasure(vector<ll> &arr, const char* format) {
    auto startTime1 = chrono::high_resolution_clock::now();
    bubble_sort(arr);
    auto endTime1 = chrono::high_resolution_clock::now();
    ld workTime1 = (endTime1 - startTime1).count();
    workTime1 /= (ld)1e6;
    printf(format, (ll)workTime1);
}

int main() {
    ifstream file1, file2, file3;
    file1.open(".\\m1_sorted.txt");
    vector<ll> firstFile = readFileUntilEOF(file1);
    sortWithMeasure(firstFile, "m1_sorted %d milliseconds\n");
    file2.open("m2_reverse.txt");
    vector<ll> secondFile = readFileUntilEOF(file2);
    sortWithMeasure(secondFile, "m2_reverse %d milliseconds\n");
    file3.open("m3_shuffle.txt");
    vector<ll> thirdFile = readFileUntilEOF(file3);
    sortWithMeasure(thirdFile, "m3_shuffle %d milliseconds\n");
    cout << flush;
}
